package com.xzkydz.all_sensor.fragment;

import android.app.Fragment;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.Spinner;

import com.serialport.ComAssistant.Java_xor;
import com.xzkydz.all_sensor.activity.MainActivity;
import com.xzkydz.all_sensor.allsensor.R;


/**
 * Created by yk on 2016/10/17.
 */

public class YaliFragment extends Fragment {

    private String str;
    private String str_number;
    private String sensor;

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        final MainActivity mActivity = (MainActivity) getActivity();
        str = null;   //校准项目
        str_number = null; //编号
//        sensor = mActivity.PRESS_SENSOR_NUM_HEX; //传感器类型
        View view = inflater.inflate(R.layout.fragment_yali_all, container, false);
        final Spinner mspinner = (Spinner) view.findViewById(R.id.sp_jiaozhuang);
        final Spinner mSpinner_ = (Spinner) view.findViewById(R.id.sp_sensor_number);
        Button button = (Button) view.findViewById(R.id.btn_jiaozhun);

        button.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                switch ((int) mspinner.getSelectedItemId()) {
                    case 0:
                        str = "00";
                        break;
                    case 1:
                        str = "88";
                        break;
                    case 2:
                        str = "01";
                        break;
                    case 3:
                        str = "02";
                        break;
                    case 4:
                        str = "04";
                        break;
                    case 5:
                        str = "10";
                        break;
                    case 6:
                        str = "20";
                        break;
                    case 7:
                        str = "40";
                        break;
                    default:
                        break;
                }

                switch ((int) mSpinner_.getSelectedItemId()) {
                    case 0:
                        str_number = "01";
                        break;
                    case 1:
                        str_number = "02";
                        break;
                    case 2:
                        str_number = "03";
                        break;
                    case 3:
                        str_number = "04";
                        break;
                    case 4:
                        str_number = "05";
                        break;
                    case 5:
                        str_number = "06";
                        break;
                    case 6:
                        str_number = "07";
                        break;
                    case 7:
                        str_number = "08";
                        break;
                    case 8:
                        str_number = "09";
                        break;
                    default:
                        break;
                }

                switch (mActivity.sensorNumber()) {
                    case 0:
                        sensor = "20";
                        break;
                    case 1:
                        sensor = "21";
                        break;
                    case 2:
                        sensor = "22";
                        break;
                    case 3:
                        sensor = "23";
                        break;
                    default:
                        break;

                }
                String data_com = "4B590801050001" + sensor + str_number + "02" + str + Java_xor.checkcode_0007("0801050001" + sensor + str_number + "02" + str);
                mActivity.ShowInf("\n\n\n" + "配置包内容：" + data_com);
                mActivity.sendPortData(data_com);  //发送数据
            }
        });
        return view;
    }
}
